package com.example.common.common.config.llm.teest;//package com.example.hello.common.config.llm;
//
//import org.springframework.ai.embedding.EmbeddingClient;
//import org.springframework.ai.openai.OpenAiEmbeddingModel;
//import org.springframework.ai.vectorstore.RedisVectorStore;
//import org.springframework.ai.vectorstore.VectorStore;
//import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.data.redis.connection.RedisConnectionFactory;
//import org.springframework.data.redis.core.RedisTemplate;
//import org.springframework.data.redis.core.ValueOperations;
//
//import javax.annotation.PostConstruct;
//import java.util.concurrent.TimeUnit;
//
//@Configuration
//public class VectorStoreConfig {
//
//    private final RedisConnectionFactory redisConnectionFactory;
//
//    public VectorStoreConfig(RedisConnectionFactory redisConnectionFactory) {
//        this.redisConnectionFactory = redisConnectionFactory;
//    }
//
//    // 检查 RediSearch 模块是否可用
//    @PostConstruct
//    public void checkRediSearchModule() {
//        try {
//            RedisTemplate<String, String> template = new RedisTemplate<>();
//            template.setConnectionFactory(redisConnectionFactory);
//            template.afterPropertiesSet();
//
//            ValueOperations<String, String> ops = template.opsForValue();
//            ops.set("__health_check__", "test", 1, TimeUnit.SECONDS);
//
//            // 尝试执行 RediSearch 命令
//            template.execute(connection -> {
//                connection.execute("FT._LIST", new byte[0]);
//                return null;
//            });
//        } catch (Exception e) {
//            throw new IllegalStateException(
//                    "Redis server does not have RediSearch module enabled. " +
//                            "Please use Redis Stack or load the RediSearch module.\n" +
//                            "Solution: docker run -p 6379:6379 redis/redis-stack:latest", e);
//        }
//    }
//
//    @Bean
//    public VectorStore vectorStore(OpenAiEmbeddingModel embeddingClient) {
//        return new RedisVectorStore(
//                RedisVectorStore.RedisVectorStoreConfig.builder()
//                        .withIndexName("products_idx")
//                        .withPrefix("doc:")
//                        .build(),
//                redisConnectionFactory,
//                embeddingClient
//        );
//    }
//}